﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：庄金冬 
    //
    // 文件名：BLL_Login.cs
    // 文件功能描述：用户登录业务逻辑类,实现接口IBLL_Login,继承自类MarshalByRefObject
    // 创建标识：庄金冬2009-03-06
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;

using System.Text;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;
using HZ.Supervise.DAL;
namespace HZ.Supervise.BLL
{
    /// <summary>
    /// 用户登录业务逻辑类,实现接口IBLL_Login,继承自类MarshalByRefObject
    /// </summary>
    public class BLL_Login : MarshalByRefObject, IBLL_Login
    {

        #region IBLL_Login 成员

        /// <summary>
        /// 用户登录0:登录失败;1:登录成功;2:用户名密码不匹配;3:用户未启用;
        /// </summary>
        /// <param name="userid">用户编号</param>
        /// <param name="userpassword">用户密码</param>
        /// <param name="user">(out)用户实例</param>
        /// <returns>0:登录失败;1:登录成功;2:用户名密码不匹配;3:用户未启用;</returns>
        public int Login(string userid, string userpassword, out User user)
        {
            userpassword = HZ.Fun.GetMd5(userpassword);

            int i = DAL_User.Login(userid, userpassword, out user);
            
            if (i == 1)
            {
                DAL_Helper.OperateTableSQL(new KeyOperationLogJG() { OperationLogSerialID = Guid.NewGuid().ToString(), OperateMessage = "登陆成功", OperateTime = DateTime.Now, Operator = userid, OrgID = user.Org.OrgID }, TableOperator.Insert);
            }

            return i;
        }

       /// <summary>
        /// 单点登录函数
        /// </summary>
        /// <param name="username"></param>
        /// <param name="userpassword">用户密码</param>
        /// <param name="User"></param>
        /// <returns>1 成功 2不存在该用户名 3系统故障</returns>
        public int SinglePointLogin(string username, string userpassword, out User account)
        {
            int i = DAL_User.Login(username, userpassword, out account);

            if (i == 1)
            {
                //DAL_Helper.OperateTableSQL(new KeyOperationLogJG() { OperationLogSerialID = Guid.NewGuid().ToString(), OperateMessage = "登陆成功", OperateTime = DateTime.Now, Operator = username }, TableOperator.Insert);
            }

            return i;
        }

        /// <summary>
        /// 用户登录0:登录失败;1:登录成功;2:用户名密码不匹配;3:用户未启用;
        /// </summary>
        /// <param name="userid">用户编号</param>
        /// <param name="userpassword">用户密码</param>
        /// <param name="user">(out)用户实例</param>
        /// <returns>0:登录失败;1:登录成功;2:用户名密码不匹配;3:用户未启用;</returns>
        public int Login(string userid, string userpassword, string RoleID, out User user)
        {

            userpassword = HZ.Fun.GetMd5(userpassword);

            int i = DAL_User.Login(userid, userpassword, RoleID, out user);           

            if (i == 1)
            {
                //DAL_Helper.OperateTableSQL(new KeyOperationLogJG() { OperationLogSerialID = Guid.NewGuid().ToString(), OperateMessage = "登陆成功", OperateTime = DateTime.Now, Operator = userid }, TableOperator.Insert);
            }
            return i;
        }
        /// <summary>
        /// 注销当前用户
        /// </summary>
        public void Logoff()
        {
            
        }
        #endregion

        /// <summary>
        /// 添加登录日志
        /// </summary> 
        public int AddLoginLog(LoginLog lg)
        {
            return DAL_User.AddLoginLog(lg);
        }
    }
}
